package filters;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import coreservlets.filters.*;

public class LowercaseFilter2 implements Filter {
  public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
      throws ServletException, IOException {
    StringWrapper responseWrapper =
      new StringWrapper((HttpServletResponse)response);
    // Invoke resource, accumulating output in the wrapper.
    chain.doFilter(request,responseWrapper);
    // Turn entire output into one big String.
    String responseString = responseWrapper.toString();
    responseString = responseString.toLowerCase();
    PrintWriter out = response.getWriter();
    out.write(responseString);
  }

  public void init(FilterConfig config) {}
  public void destroy() {}
}
